// 云函数入口文件
const cloud = require('wx-server-sdk')
var request = require('request')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async(event, context) => {
  var os = event.os
  var fee = event.fee
  var hostId = event.hostId
  var slotId = event.slotId
  var userId = event.userId
  var token = event.token
  console.log(os,fee,hostId,slotId,userId,token)
  return new Promise((resolve, reject) => {
    request.post('http://47.104.75.15/campus/api/power/on?os=' + os + '&fee=' + fee + '&hostId=' + hostId +'&slot=' + slotId + '&userId=' + userId + '&token=' +token,
     (error, response, body) => {
      if (error) {
        reject()
      } else {
        try {
          resolve(body)
        } catch (e) {
          reject()
        }
      }
    })
  })
}